import 'package:dio/dio.dart';
import 'package:mi_mang_flutter/config/configs.dart';
import 'package:mi_mang_flutter/manager/app_manager.dart';
import 'package:mi_mang_flutter/model/daily_word_model.dart';
import 'package:mi_mang_flutter/model/public/page_model.dart';
import 'package:mi_mang_flutter/network/extra_keys.dart';
import '../model/public/entity_factory.dart';
import '../network/response_data.dart';
import '../network/client.dart';

/// 获取每日一句
class DailyWordsApi {
  /// 分页获取每日一句
  static const String _API_DAILY_WORDS_GET_PAGE = "/api/daily-words/get_page";

  /// 分页获取每日一句
  /// [pageNum]
  /// [pageSize]
  static Future<ResponseData<PageModel<DailyWordModel>>> getDailyWordsPage({
    int pageNum = 1,
    int pageSize = Configs.NETWORK_PAGE_SIZE,
    int? connectTimeout,
  }) async {
    var response = await client.get(
      _API_DAILY_WORDS_GET_PAGE,
      queryParameters: {
        "pageNum": pageNum,
        "pageSize": pageSize,
      },
      options: Options(
        sendTimeout: Duration(milliseconds: connectTimeout ?? 10000),
        extra: {
          ExtraKeys.NEED_TOKEN: AppManager.isLogin(),
        },
      ),
    );
    return ResponseData<PageModel<DailyWordModel>>(
        code: response.code,
        msg: response.msg,
        data: EntityFactory.generatePageOBJ(response.data));
  }
}
